const router = require("koa-router")()
const MovieModel = require("../../models/movie")
router.get('/api/search',async ctx=>{
    var {keyword} = ctx.query
    // var reg = new RegExp(keyword)
    let tables = ["top250","inTheaters","comingSoon"]
    let searchMovies = []
    for(let item of tables){
        let res = await MovieModel(item).find({title:{$regex:keyword}})
        searchMovies.push(...res)
    }
    ctx.body={
        code:200,
        result:searchMovies,
        total:searchMovies.length,
        msg:"电影搜索"
    }
})
module.exports = router